<?php
//热门商品
class Controller_Admin_HotGoods extends Controller_Form
{
    public function __construct ($req, $res)
    {
        $this->_form_type = 'hotgoods';
        parent::__construct($req, $res);

        $this->_list_where = array(
        );

        $this->_sort_extra_columns = array(
            array('changed', DB::expr('curdate()')),
        );

        $this->_shopId = App_Shop_Manager::currentShopId();
        if ($this->_shopId > 0)
            $this->_list_where[] = array('shopId', '=', $this->_shopId);
    }

	//首页
    public function action_index ()
    {
        $this->action_list();
    }

	//添加热卖商品
    public function action_create ()
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }

        parent::action_create();
    }

	//修改热卖
	//$nid int 商品id
    public function action_update ($nid)
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }
        else
        {
            $data = App_Hot::detail($nid);
            $this->_form_data = $data;
        }

        parent::action_update($nid);
    }

	//详细信息
	//$nid int 商品id
    public function action_detail ($nid)
    {
        $data = App_Hot::detail($nid);
        $this->_form_data = $data;

        parent::action_detail($nid);
    }

	//数据格式重构
    private function rebuild_post_data (& $post)
    {
        $post['uid']   = user::current_user_id();
    }

    public function list_filter_data (& $rows)
    {
    }

    public function list_get_data ($offset, $limit)
    {
        return App_Hot::items ('GOODS', $offset, $limit, $this->_shopId);
    }
}
